package main

import "fmt"

func main() {
	fmt.Println(7%-3, 7%3, -7%3, -7%-3)
	/*if 7/3 == 2 && 7/3 > 1 {
		fmt.Println(1)
	}
	if 3 > 2 || 3 < 2 {
		fmt.Println(2)
	}*/

	/*
		& 位运算 AND
		| 位运算 OR
		^ 位运算 XOR -- 位操作运算符 ^ 作为二元运算符时是按位异或（XOR），当用作一元运算符时表示按位取反
		&^ 位清空 (AND NOT) -- 如果对应y中bit位为1的话, 表达式 z = x &^ y 结果z的对应的bit位为0，否则z对应的bit位等于x相应的bit位的值
		<< 左移
		>> 右移
	*/

	var x uint8 = 1<<1 | 1<<5
	var y uint8 = 1<<1 | 1<<2
	var x1 uint8 = 1 << 1
	fmt.Printf("%08b\n", x1)   // "00000010"
	fmt.Printf("%08b\n", x)    // "00100010", the set {1, 5}
	fmt.Printf("%08b\n", y)    // "00000110", the set {1, 2}
	fmt.Printf("%08b\n", x&y)  // "00000010", the intersection {1}
	fmt.Printf("%08b\n", x|y)  // "00100110", the union {1, 2, 5}
	fmt.Printf("%08b\n", x^y)  // "00100100", the symmetric difference {2, 5}
	fmt.Printf("%08b\n", x&^y) // "00100000", the difference {5}
	for i := uint(0); i < 8; i++ {
		if x&(1<<i) != 0 { // membership test
			fmt.Println(i) // "1", "5"
		}
	}
	fmt.Printf("%08b\n", x<<1) // "01000100", the set {2, 6}
	fmt.Printf("%08b\n", x>>1) // "00010001", the set {0, 4}

	var j int = -1
	var i int = 1
	T1 := fmt.Sprintf("%T", j)
	T2 := fmt.Sprintf("%T", i)
	fmt.Println(T1, T2, T1 == T2)
	fmt.Printf("%08b\n", j)
	fmt.Printf("%08b\t%d\t%08b\t%d\n", j>>1, j>>1, j<<1, j<<1)
	fmt.Printf("%08b\n", i)
	fmt.Printf("%08b\t%d\t%08b\t%d\n", i>>1, i>>1, i<<1, i<<1)

	f := 3.141 // a float64
	k := int(f)
	fmt.Println(f, k) // "3.141 3"
	f = 1.99
	fmt.Println(int(f)) // "1"

	g := 1e100       // a float64
	fmt.Println((g)) // 结果依赖于具体实现

	o := 0666
	fmt.Printf("%d %[1]o %#[1]o\n", o) // "438 666 0666"
	fmt.Printf("%d %[1]x %#[1]x %#[1]X\n", int64(0xdeadbeef))
	// Output:
	// 3735928559 deadbeef 0xdeadbeef 0XDEADBEEF

	ascii := 'a'
	unicode := '国'
	newline := '\n'
	fmt.Printf("%d %[1]c %[1]q\n", ascii)   // "97 a 'a'"
	fmt.Printf("%d %[1]c %[1]q\n", unicode) // "22269 国 '国'"
	fmt.Printf("%d %[1]q\n", newline)       // "10 '\n'"

}
